package lab7;
/**
 * Title: MathProblem and MyMath classes for CSIS 235 Lab #7
 * Description: CS 235 Lab #7 - MathProblem class
 *              This class has a main method - it is the client of the MyMath class.
 *              The MyMath class has a single method that is used in the MathProblem class
 *              
 * @author Anthony Varghese 
 * @author 
 * @email  your.n.here@my.uwrf.edu
 * @date   March 17th 2013
 */

import java.util.Scanner;

/**
 * MyMath class - server for MathProblem class
 * @author Anthony Varghese
 *
 */
class MyMath{
	/**
	 * 
	 * @param x
	 * @return
	 */
	public double compute(double x){
		double y = 1.0 + x;
		return Math.sqrt( 1/ y );
	}
}

/**
 * MathProblem class - client of MyMath
 * @author Anthony Varghese
 *
 */
public class MathProblem {
	/**
	 * main method - program starts here
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner console = new Scanner( System.in );
		MyMath m = new MyMath();
		
		System.out.println("This program will compute a function for a range of values that you specify\n");
		System.out.print(" Please enter a valid double-precision number: " );
		final double user_input1 = console.nextDouble();
		System.out.print(" OK, thanks, now please enter a second double-precision number: " );
		final double user_input2 = console.nextDouble();
		
		final int iterations = 20;
		final double increment = (user_input2 - user_input1)/iterations;
		
		for (int i=0; i<=iterations; i++) {
			final double testvalue = user_input1 + i*increment;
			final double result = m.compute( testvalue ); 
			System.out.println("  " + testvalue + " -->  " + result );
		}
		System.out.println("Done!");
		console.close();
	}
}
